//-----------------------------------------------------
// nebulaState.cpp
//-----------------------------------------------------

/**
 * @file nebulaState.cpp
 *
 * Contains the class that represents a state of the Nebula application.
 * All the states of the application that want to use Nebula for drawing
 * must extend this class and implement it's virtual methods.
 *
 * @see application::CApplicationState
 * @see application::CApplication
 *
 */

#include "nebulaState.h"
#include "nebulaApplication.h"

#include <tools/nmayacamcontrol.h>

namespace application {

	CNebulaState::CNebulaState(CNebulaApplication *app) : CApplicationState(app),
		_nebulaApp(app), _camControl(0) {}

	CNebulaState::~CNebulaState() 
	{
		if (_camControl)
			delete _camControl;
	}

	void CNebulaState::onCreate()
	{
		CApplicationState::onCreate();
		_camControl = new nMayaCamControl();
		_camControl->Initialize();
	}

	void CNebulaState::onDestroy()
	{
		CApplicationState::onDestroy();
	}

	void CNebulaState::onActivate()
	{
		CApplicationState::onActivate();
	}

	void CNebulaState::onDeactivate()
	{
		CApplicationState::onDeactivate();
	}

	void CNebulaState::onRun()
	{
		CApplicationState::onRun();
	}

	void CNebulaState::resetDefaultCamera()
	{
		if (!_camControl)
			_camControl = new nMayaCamControl();
		else
			_camControl->Reset();
	}

	void CNebulaState::updateDefaultCamera()
	{
		// TODO: read user input and move camera

		setCameraMatrix(_camControl->GetViewMatrix());
	}

	void CNebulaState::runLogic()
	{
		updateDefaultCamera();
	}

	void CNebulaState::processHUDCommandQueue()
	{
		// TODO: process HUD command queue

	}

	void CNebulaState::processHUDCommand(std::string command)
	{
		// By default implement the state changes for the application
		char copyCommand[128];
		strcpy(copyCommand, command.c_str());
		char *token = strtok(copyCommand, " ");
		if (strcmp(token, "changeAppState") == 0)
		{
			token = strtok(NULL, " ");
			_nebulaApp->setState(token);
		}
	}

	void CNebulaState::processUserInput()
	{
		// TODO: By default process user input to modify the camera position

	}

} // namespace application